/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.camachosanchez.reportes.nuevos;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import java.io.IOException;

/**
 *
 * @author Rolando
 */
public class ReporteUtil {

    public static PdfPTable getCabeceraReporte(String titulo, String subtitulo, String periodo) {
        PdfPTable cabecera = new PdfPTable(2);
        cabecera.setWidthPercentage(100);
        try {
            BaseFont bf1 = BaseFont.createFont("cour.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
            Font fuenteTitulos = new Font(bf1, 10);
            fuenteTitulos.setStyle(Font.BOLD);

            Font fuenteSubtitulos = new Font(bf1, 9);

            PdfPCell cell;
            Chunk chunk = new Chunk(titulo.toUpperCase(), fuenteTitulos);
            cell = new PdfPCell(new Phrase(chunk));
            cell.setBorder(0);
            cabecera.addCell(cell);

            Image image = Image.getInstance("logo.jpg");
            image.scaleToFit(105f, 35f);
            cell = new PdfPCell(image);
            cell.setRowspan(3);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setBorder(0);
            cabecera.addCell(cell);

            chunk = new Chunk(subtitulo, fuenteSubtitulos);
            cell = new PdfPCell(new Phrase(chunk));
            cell.setBorder(0);
            cabecera.addCell(cell);

            chunk = new Chunk(periodo, fuenteSubtitulos);
            cell = new PdfPCell(new Phrase(chunk));
            cell.setBorder(0);
            cabecera.addCell(cell);
            return cabecera;
        } catch (Exception ex) {
            ex.printStackTrace();
            cabecera = null;
        } finally {
            return cabecera;
        }
    }

    public static PdfPCell getCeldaCabeceraTabla(String valor, int colspan, BaseColor color, int... atributos) {
        PdfPCell cell = null;
        try {
            BaseFont bf1 = BaseFont.createFont("cour.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
            Font fuenteTitulos = new Font(bf1, 7);
            Chunk chunk;
            if (fuenteTitulos != null) {
                chunk = new Chunk(valor, fuenteTitulos);
            } else {
                chunk = new Chunk(valor);
            }
            cell = new PdfPCell(new Phrase(chunk));
            cell.setColspan(colspan);
            cell.setBackgroundColor(color);
            if (atributos.length > 0) {
                cell.setHorizontalAlignment(atributos[0]);
                if (atributos.length > 1) {
                    cell.setBorder(atributos[1]);
                }
            }
            cell.setBorder(1);
            cell.setBorderColor(BaseColor.WHITE);
        } catch (DocumentException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return cell;
    }
}
